﻿USE [master]
GO
/****** Object:  Database [MirisHumanMilkAnalyser]    Script Date: 03/17/2014 11:43:14 ******/
CREATE DATABASE [MirisHumanMilkAnalyser]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'MirisHumanMilkAnalyser', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\MirisHumanMilkAnalyser.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'MirisHumanMilkAnalyser_log', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\MirisHumanMilkAnalyser_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET COMPATIBILITY_LEVEL = 110
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [MirisHumanMilkAnalyser].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET ARITHABORT OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET  DISABLE_BROKER 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET  MULTI_USER 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET DB_CHAINING OFF 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
USE [MirisHumanMilkAnalyser]
GO
/****** Object:  Table [dbo].[AnalysisItem]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AnalysisItem](
	[ItemName] [nvarchar](50) NOT NULL,
	[ItemTitle] [nvarchar](50) NOT NULL,
	[ItemUsage] [nvarchar](50) NOT NULL,
	[DietaryRecommendation] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_AnalysisItem] PRIMARY KEY CLUSTERED 
(
	[ItemName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AnalysisResult]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AnalysisResult](
	[SampleNumber] [nvarchar](50) NOT NULL,
	[PatientNumber] [nvarchar](50) NOT NULL,
	[SampleType] [tinyint] NOT NULL,
	[SampleStageType] [tinyint] NOT NULL,
	[TestDate] [datetime] NOT NULL,
	[Fat] [float] NOT NULL,
	[CrudeProtein] [float] NOT NULL,
	[Carbohydrate] [float] NOT NULL,
	[TS] [float] NOT NULL,
	[Energy] [float] NOT NULL,
	[TrueProtein] [float] NOT NULL,
	[AttachedDiagnosticMessage] [nvarchar](50) NULL,
 CONSTRAINT [PK_AnalysisResult_1] PRIMARY KEY CLUSTERED 
(
	[SampleNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_AnalysisResult] UNIQUE NONCLUSTERED 
(
	[SampleNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AnalysisResultDiagnosticMessage]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AnalysisResultDiagnosticMessage](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[SampleNumber] [nvarchar](50) NOT NULL,
	[MessageContent] [nvarchar](200) NOT NULL,
 CONSTRAINT [PK_AnalysisResultDiagnosticMessage] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BreastfeedingSignificance]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BreastfeedingSignificance](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](20) NOT NULL,
	[SignificanceContent] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_BreastfeedingSignificance] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DiagnosticMessageReference]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DiagnosticMessageReference](
	[MessageTimestamp] [nvarchar](100) NOT NULL,
	[OrderIndex] [smallint] NOT NULL,
	[MessageContent] [nvarchar](200) NOT NULL,
 CONSTRAINT [PK_DiagnosticMessage] PRIMARY KEY CLUSTERED 
(
	[MessageTimestamp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Patient]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Patient](
	[Number] [nvarchar](50) NOT NULL,
	[MotherName] [nvarchar](10) NOT NULL,
	[MotherAge] [smallint] NULL,
	[MotherHeight] [float] NULL,
	[MotherWeight] [float] NULL,
	[MotherBMI] [float] NULL,
	[MotherOpenMilkDate] [date] NOT NULL,
	[MotherDeliveryMode] [nvarchar](10) NOT NULL,
	[MotherEmotion] [nvarchar](100) NULL,
	[MotherBadHabit] [nvarchar](100) NULL,
	[BabyName] [nvarchar](10) NOT NULL,
	[BabyGender] [smallint] NOT NULL,
	[BabyBirthday] [date] NOT NULL,
	[IsBabyPrematureDelivery] [bit] NOT NULL,
	[BabyHeight] [float] NULL,
	[BabyWeight] [float] NULL,
	[BabyHeadCircumference] [float] NULL,
	[BabyBirthHeight] [float] NULL,
	[BabyBirthWeight] [float] NULL,
	[BabyBirthHeadCircumference] [float] NULL,
	[Apgar] [float] NULL,
	[CreateOn] [datetime] NOT NULL,
	[UpdateOn] [datetime] NOT NULL,
 CONSTRAINT [PK_Patient_1] PRIMARY KEY CLUSTERED 
(
	[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_Patient] UNIQUE NONCLUSTERED 
(
	[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UnassignedSampleNumber]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UnassignedSampleNumber](
	[SampleNumber] [nvarchar](50) NOT NULL,
	[GenerateDate] [date] NOT NULL,
 CONSTRAINT [PK_UnassignedSampleNumber] PRIMARY KEY CLUSTERED 
(
	[SampleNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  View [dbo].[PatientAnalysisDataView]    Script Date: 03/17/2014 11:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[PatientAnalysisDataView]
AS
SELECT     dbo.Patient.Number AS '编号', dbo.Patient.MotherName AS '母亲姓名', dbo.Patient.MotherAge AS '母亲年龄', dbo.Patient.BabyName AS '婴儿姓名', 
                      dbo.Patient.BabyBirthday AS '婴儿出生日期', CASE WHEN dbo.Patient.BabyGender = 0 THEN '女' ELSE '男' END AS '婴儿性别', 
                      dbo.AnalysisResult.SampleNumber AS '样本号', 
                      CASE WHEN dbo.AnalysisResult.SampleType = 1 THEN '前段' WHEN dbo.AnalysisResult.SampleType = 2 THEN '中段' WHEN dbo.AnalysisResult.SampleType = 3 THEN
                       '后段' WHEN dbo.AnalysisResult.SampleType = 4 THEN '全乳' END AS '母乳取样', 
                      CASE WHEN dbo.AnalysisResult.SampleStageType = 1 THEN '初乳' WHEN dbo.AnalysisResult.SampleStageType = 2 THEN '过渡乳' WHEN dbo.AnalysisResult.SampleStageType
                       = 3 THEN '成熟乳' END AS '母乳分期', dbo.AnalysisResult.TestDate AS '测试日期', dbo.AnalysisResult.Fat AS '脂肪', dbo.AnalysisResult.CrudeProtein AS '总蛋白质', 
                      dbo.AnalysisResult.TrueProtein AS '真蛋白质', dbo.AnalysisResult.Carbohydrate AS '糖类', dbo.AnalysisResult.TS AS '干物质', 
                      dbo.AnalysisResult.Energy AS '总能量'
FROM         dbo.Patient INNER JOIN
                      dbo.AnalysisResult ON dbo.Patient.Number = dbo.AnalysisResult.PatientNumber

GO
ALTER TABLE [dbo].[AnalysisResult]  WITH CHECK ADD  CONSTRAINT [FK_AnalysisResult_Patient] FOREIGN KEY([PatientNumber])
REFERENCES [dbo].[Patient] ([Number])
GO
ALTER TABLE [dbo].[AnalysisResult] CHECK CONSTRAINT [FK_AnalysisResult_Patient]
GO
ALTER TABLE [dbo].[AnalysisResultDiagnosticMessage]  WITH CHECK ADD  CONSTRAINT [FK_AnalysisResultDiagnosticMessage_AnalysisResult] FOREIGN KEY([SampleNumber])
REFERENCES [dbo].[AnalysisResult] ([SampleNumber])
GO
ALTER TABLE [dbo].[AnalysisResultDiagnosticMessage] CHECK CONSTRAINT [FK_AnalysisResultDiagnosticMessage_AnalysisResult]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[22] 4[14] 2[25] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "AnalysisResult"
            Begin Extent = 
               Top = 6
               Left = 282
               Bottom = 125
               Right = 506
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Patient"
            Begin Extent = 
               Top = 6
               Left = 544
               Bottom = 125
               Right = 773
            End
            DisplayFlags = 280
            TopColumn = 9
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 17
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'PatientAnalysisDataView'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'PatientAnalysisDataView'
GO
USE [master]
GO
ALTER DATABASE [MirisHumanMilkAnalyser] SET  READ_WRITE 
GO